﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TribesPSO;

namespace TribesPSOTest.NUnit
{
    public class Rosenbrock:IObjectiveFunction
    {
        int evaluations;

        public int Evaluations
        {
            get { return evaluations; }
        }

        public int Dimensions
        {
            get { return 2; }
        }

        public EuclidianVector MinBounds
        {
            get { return new EuclidianVector(-5, -5); }
        }

        public EuclidianVector MaxBounds
        {
            get { return new EuclidianVector(5, 5); }
        }

        public EuclidianVector InitialGuess
        {
            get { return null; }
        }

        public double Evaluate(EuclidianVector Position)
        {
            evaluations++;
            return Math.Pow(1 - Position[0], 2) + 100 * Math.Pow(Position[1] - (Position[0] * Position[0]), 2);
        }

        public bool TryEvaluate(EuclidianVector Position, double AbortValue, out double Result)
        {
            evaluations++;
            Result = Math.Pow(1 - Position[0], 2) + 100 * Math.Pow(Position[1] - (Position[0] * Position[0]), 2);
            return true;
        }

        public Rosenbrock()
        {
            evaluations = 0;

        }
    }
}
